/*
 * Nombre de Clase:	accesoDao
 * Nombre de Clases Asociadas:
 * Informacion de version: 1.0
 * Fecha Creacion: 01/08/2007  
 * Autor Original: Davis Carhuancho
 * Descripcion: 
 * Fecha Ultima Modificacion - Responsable Ultima Modificacion - Descripcion Ultima Modificacion
 * Copyright  
 */


package com.unmsm.eciebt.dao;


import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.CallableStatement;
import java.sql.SQLException;
import java.sql.Statement;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;


public class accesoDao {

	protected DataSource dataSource = null;

	protected Connection conn = null;
	protected ResultSet rs = null;
	protected ResultSet rs1 = null;
	protected Statement stm = null;
	protected PreparedStatement pstm = null;
	protected CallableStatement cs = null;

	public accesoDao()
		throws accesoDaoException {
		String resourceName = "jdbc/Incubadora";
		try {
			Context initContext = new InitialContext();
			Context envContext  = (Context)initContext.lookup("java:/comp/env");
			dataSource = (DataSource)envContext.lookup(resourceName);
		} catch(NamingException e) {
			throw new accesoDaoException(
				"Cannot locate data source at " + resourceName, e );
		}
	}
	
	public accesoDao(DataSource dataSource) {
		this.dataSource = dataSource;
	}
	
	public void closeResultSet(ResultSet rs)
		throws accesoDaoException {
		if (rs!=null) {
			try {
				rs.close();
			} catch (SQLException e) {
				System.err.println(e.getMessage());
				throw new accesoDaoException("SQL Exception ", e );
			}
		}
	}
	
	public void closeStatement(Statement stm)
		throws accesoDaoException {
		if (stm!=null) {
			try {
				stm.close();
			} catch (SQLException e) {
				System.err.println(e.getMessage());
				throw new accesoDaoException("SQL Exception ", e );
			}
		}
	}
	
	public void closePreparedStatement(PreparedStatement pstm)
		throws accesoDaoException {
		if (pstm!=null) {
			try {
				pstm.close();
			} catch (SQLException e) {
				System.err.println(e.getMessage());
				throw new accesoDaoException("SQL Exception ", e );
			}
		}
	}

	public void closeCallableStatement(CallableStatement cstm)
	throws accesoDaoException {
	if (cstm!=null) {
		try {
			cstm.close();
		} catch (SQLException e) {
			System.err.println(e.getMessage());
			throw new accesoDaoException("SQL Exception ", e );
		}
	}
}
	
	public void closeConnection(Connection conn)
		throws accesoDaoException {
		if (conn!=null) {
			try {
				conn.close();
			} catch (SQLException e) {
				System.err.println(e.getMessage());
				throw new accesoDaoException("SQL Exception ", e );
			}
		}
	}

}
